
package org.soekrat.engine.suite;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

public final class Suite 
{
  private final Class<?> m_class;
  
  private final Map<String, ClassMetaData> m_classes=
    new HashMap<String, ClassMetaData>();
  
  private final Map<Locale, Map<String, ClassMetaData>> m_bynames=
    new HashMap<Locale, Map<String,ClassMetaData>>();
  
  public Suite(Class<?> clazz) 
  {
    if (clazz==null)
    {
      throw new NullPointerException("clazz");
    }
    
    m_class=clazz;
  }
  
  public void addClass(ClassMetaData cmd)
  {
    if (cmd==null)
    {
      throw new NullPointerException("cmd");
    }
    
    Class<?> clazz=cmd.getClass();
    String cname=clazz.getName();
    
    if (m_class.isAssignableFrom(clazz))
    {
      m_classes.put(cname, cmd);
      
      Locale[] locales=cmd.getLocales();
      for (Locale locale : locales) 
      {
        Map<String, ClassMetaData> cmds=m_bynames.get(locale);
        if (cmds==null)
        {
          cmds=new HashMap<String, ClassMetaData>();
          m_bynames.put(locale, cmds);
        }
        
        String[] names=cmd.getNames(locale);
        for (String name : names) cmds.put(name, cmd);
      }
    }
    else
    {
      throw new IllegalArgumentException(cname+" is not "+m_class.getName());
    }
  }
  
  @Override
  public String toString() 
  {
    // TODO Auto-generated method stub
    return super.toString();
  }
  
}
